package com.fhz.module_main.ui

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.viewModels
import androidx.fragment.app.FragmentPagerAdapter
import androidx.fragment.app.viewModels
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.alibaba.android.arouter.facade.annotation.Route
import com.fhz.lib_base.ARouterPath
import com.fhz.module_main.R
import com.fhz.module_main.adapter.IndexViewPageAdapter
import com.fhz.module_main.databinding.FragmentMainBinding
import com.fhz.module_main.ui.index.DailyFragment
import com.fhz.module_main.ui.index.FindFragment
import com.fhz.module_main.ui.index.RecommendFragment
import com.fhz.module_main.viewmodel.IndexViewModel
import com.fhz.module_main.viewmodel.RecommendViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = ARouterPath.MAIN_INDEX)
/**
 * A simple [Fragment] subclass.
 * Use the [MainFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class MainFragment : Fragment() {

    private lateinit var binding: FragmentMainBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        binding = FragmentMainBinding.inflate(inflater, container, false)

        var list  = mutableListOf<Fragment>()
        list.add(FindFragment())
        list.add(RecommendFragment())
        list.add(DailyFragment())

        binding.indexVp.adapter = IndexViewPageAdapter(list,childFragmentManager,
            FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
        )

        //tablayout
        binding.tabLayout.setViewPager(binding.indexVp, arrayOf("发现","推荐","日报"))
        //默认展示页
        binding.indexVp.currentItem = 1

        return binding.root
    }

}